package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@WebServlet("/demo")
public class DemoServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取get请求的全部数据
        String url = req.getRequestURL().toString();
        System.out.println(req);
        System.out.println(url);
        String queryString = req.getQueryString();//获取不到post请求体中的数据
        System.out.println("get:"+queryString);


        //获取POST提交中请求体中数据
    /*    BufferedReader reader = req.getReader();
        String str="";
        while ((str=reader.readLine())!=null){
            System.out.println("post:"+str);
        }*/

        System.out.println("======================================");
        String ageStr = req.getParameter("userAge");
        System.out.println("ageStr:"+ageStr);
        Integer age=Integer.parseInt(ageStr);
        String birthdayStr = req.getParameter("birthday");
        try {
            Date birthday=new SimpleDateFormat("yyyy-MM-dd").parse(birthdayStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String hobby = req.getParameter("hobby");
        System.out.println("hobby:"+hobby);
        String[] hobbies = req.getParameterValues("hobby");


        Map<String, String[]> parameterMap = req.getParameterMap();
    }
}



























































































































































































































